﻿@model Bricks.Business.Models.ProjectContract.ProjectInfo

@{
    ViewBag.Title = "在建项目概况";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        initTable();
    });
    function initTable(queryData) {
        $('#projectDataGrid').datagrid({
            url: '/ProjectInfo/GetDataList',
            //title: '功能管理',  //标识
            iconCls: 'icon-bricks',
            //width: 'auto',
            //height: 500,
            nowrap: true,
            autoRowHeight: false,
            striped: true,
            collapsible: true,
            pagination: false,
            //pageSize: 20,
            rownumbers: true,
            //sortName: 'ID',    //根据某个字段给easyUI排序
            //sortOrder: 'asc',
            remoteSort: false,
            idField: 'ID',
            checkOnSelect: true,
            selectOnCheck: true,
            singleSelect: true,
            queryParams: queryData,  //异步查询的参数
            toolbar: '#projectToolBar',
            columns: [[
                { title: '@Html.LabelFor(model => model.ProjectCode)', field: 'ProjectCode', width: 100, sortable: true },
                { title: '@Html.LabelFor(model => model.ProjectName)', field: 'ProjectName', width: 450, sortable: true },
                { title: '@Html.LabelFor(model => model.RegisterUserID)', field: 'RegisterUser', width: 80, sortable: true },
                { title: '@Html.LabelFor(model => model.RegisterDate)', field: 'RegisterDate', width: 100, sortable: true },
                { title: '@Html.LabelFor(model => model.BuildType)', field: 'BuildType', width: 100, sortable: true },
                { title: '@Html.LabelFor(model => model.InvestType)', field: 'InvestType', width: 100, sortable: true },
                { title: '@Html.LabelFor(model => model.Description)', field: 'Description', width: 300, sortable: true },
                {
                    title: '@Html.LabelFor(model => model.IsDeleted)', field: 'IsDeleted', width: 60, sortable: true, align: "center",
                    formatter: function (value, row, index) {
                        return $.GetYesOrNo(value);  //是否禁用图标（是/否）
                    }
                }
            ]],
            //双击弹出预览
            onDblClickRow: function (rowIndex, rowData) {
                ProjectInfo.Preview();
            }
        });
    }
    var ProjectInfo = {
        //新增
        Add: function () {
            ProjectInfo.Mutual("新增", "/ProjectInfo/Edit", true);
        },

        //修改
        Modify: function () {
            var row = $("#projectDataGrid").datagrid("getSelected");
            if (row) {
                ProjectInfo.Mutual("修改", "/ProjectInfo/Edit?ID=" + row.ID);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //实体操作
        Mutual: function (title, href, isAdd) {
            $.ModelDialog({
                title: title, href: href, width: 690,
                handler: function () {
                    $.ModelForm({
                        validate: true, button: $(this),
                        id: "#project-model",
                        url: "/ProjectInfo/EditPost",
                        success: function (result) { ProjectInfo.Reload(); }
                    });
                },
                onLoad: function () { ProjectInfo.FormInit(isAdd); }
            });
        },

        //弹窗初始化
        FormInit: function (isAdd) {
            //定义功能类型枚举下拉
            //$("#buildType").combobox({
            //    editable: false, width: 155, panelHeight: "auto",
            //    data: [
            //        { value: "0", text: "权限标识" },
            //        { value: "1", text: "功能按钮" }
            //    ]
            //});

            //$("#buildType").combobox({
            //    width: 150, panelHeight: "auto",
            //    url: "/Dictionary/GetDictionaryByTypeTag?typeTag=BuildType",
            //    valueField: 'DictionaryName',
            //    textField: 'DictionaryName',
            //    //如果是新增，则让下拉框默认选中第一个
            //    onLoadSuccess: function () {
            //        if (true) {
            //            var data = $('#buildType').combobox('getData');
            //            if (data.length > 0) {
            //                $('#buildType').combobox('select', data[0]["DictionaryName"]);
            //            }
            //        }
            //    }
            //});

            $.DictionaryComboList("#buildType", "BuildType", isAdd);  //建设类别
            $.DictionaryComboList("#investType", "InvestType", isAdd);  //投资类别
        },


        //预览
        Preview: function () {
            var row = $("#projectDataGrid").datagrid("getSelected");
            if (row) {
                ProjectInfo.PreviewMutual("预览", "/ProjectInfo/Preview?id=" + row.ID);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //实体操作
        PreviewMutual: function (title, href) {
            $.ModelDialog({
                title: title, href: href, width: 690,
                onLoad: function () { }
            });
        },

        Enable: function () {
            ProjectInfo.SetEnable("True");
        },

        Disable: function () {
            ProjectInfo.SetEnable("False");
        },

        //设置启用或禁用
        SetEnable: function (isEnable) {
            var row = $("#projectDataGrid").datagrid("getSelected");
            if (row) {
                $.post("/ProjectInfo/SetEnable", { id: row.ID, isEnable: isEnable }, function (result) {
                    if (result.ResultType == 0) {
                        $.EasyuiSlide(result.Message);
                        ProjectInfo.Reload();
                    }
                    else {
                        $.EasyuiMsg(result.Message);
                    }
                });
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //删除
        Delete: function () {
            var arr = $('#projectDataGrid').datagrid('getSelections');

            if (arr.length == 1) {
                $.messager.confirm('操作提示', "确认删除[ " + arr[0].ProjectName + " ]吗？", function (r) {
                    if (r) {
                        $.post("/ProjectInfo/Delete?ID=" + arr[0].ID, { query: arr.join(",") }, function (result) {
                            if (result.ResultType == 0) {  //0表示成功
                                //移除删除的数据
                                //$("#myTreeGrid").datagrid("reload");
                                //$("#myTreeGrid").datagrid("clearSelections");
                                //$.messager.alert('操作提示', '删除成功!', 'info');
                                $.EasyuiSlide(result.Message);
                                ProjectInfo.Reload();
                            }
                            else {
                                $.EasyuiMsg(result.Message);
                            }
                        });
                    }
                });

            } else {
                //$.messager.alert('操作提示', '请选择一条数据!', 'warning');
                $.EasyuiMsg("请选择一条数据");
            }
            return false;
        },

        //向上
        Up: function () {
            ProjectInfo.Order("Up");
        },

        //向下
        Down: function () {
            ProjectInfo.Order("Down");
        },

        //向上或向下方法
        Order: function (order) {
            var row = $("#projectDataGrid").datagrid("getSelected");
            if (row) {
                //id：识别当前记录；pid：识别涉及调整的记录集合；order：向上或向下
                $.post("/ProjectInfo/SetOrder", { id: row.ID, order: order }, function (result) {
                    if (result.ResultType == 0) {
                        $.EasyuiSlide(result.Message);  //成功则右下角提示
                        ProjectInfo.Reload();
                        //$("#myTreeGrid").treegrid("selectRecord", row.ID);  //重新选中对应ID的记录（此处不生效，原因不明，后续探究）
                    }
                    else {
                        $.EasyuiMsg(result.Message);  //失败则弹出框提示
                    }
                });
            }
            else { $.EasyuiSlide(nullrowmsg); }
        },

        //刷新
        Reload: function () {
            $("#projectDataGrid").datagrid("reload");
        }
    }
</script>

<div class="easyui-panel" title="项目列表" fit="true">
    <table id="projectDataGrid" fit="true"></table>
    @*<div id="projectToolBar">
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='ProjectInfo.Add()' data-options='plain:true,iconCls:"icon-application_add"'>新增</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='ProjectInfo.Modify()' data-options='plain:true,iconCls:"icon-application_delete"'>修改</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='ProjectInfo.Delete()' data-options='plain:true,iconCls:"icon-bell"'>删除</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='ProjectInfo.Disable()' data-options='plain:true,iconCls:"icon-bank"'>禁用</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='ProjectInfo.Enable()' data-options='plain:true,iconCls:"icon-bestseller"'>启用</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='ProjectInfo.Up()' data-options='plain:true,iconCls:"icon-up"'>向上</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='ProjectInfo.Down()' data-options='plain:true,iconCls:"icon-down"'>向下</a>
        <a href='javascript:void(0)' class='easyui-linkbutton' onclick='ProjectInfo.Reload()' data-options='plain:true,iconCls:"icon-blue_lego"'>刷新</a>
    </div>*@
    <div id="projectToolBar">@Html.Raw(ViewBag.ToolBarInfo)</div>
</div>
